package com.aspect;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class TimeAspect {
	private static final Logger logger = LogManager.getLogger(TimeAspect.class);

	@Around("@annotation(com.aspect.TimeOnIt)")
	public void timeMeasure(ProceedingJoinPoint jp) throws Throwable {
		logger.debug("enter joinpount");
		long begin = System.currentTimeMillis();
		jp.proceed();
		logger.debug("Method " + jp.getSignature().toShortString() + " used " + (System.currentTimeMillis() - begin)
				+ "millis");
	}
}
